﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Class1
    {
        public void ZG
        {
              string constr = "Server=.;user=sa;pwd=123456;database=Demo;";
        SqlConnection sqlConnection = new SqlConnection(constr);
            try
            {
                sqlConnection.Open();
                string sql = "select * from staff";
        SqlCommand mycom = new SqlCommand(sql, sqlConnection);
        SqlDataReader myda = mycom.ExecuteReader();
                for (int i = 0; i<myda.FieldCount; i++)
                {
                    Console.Write(myda.GetName(i) + "\t");


                }
    Console.WriteLine();

                while (myda.Read())
                {
                    for (int i = 0; i<myda.FieldCount; i++)
                    {

                        Console.Write(myda[i].ToString() + "\t");

                    }
Console.WriteLine();
                }
                  catch (Exception ex)
                {
                    Console.WriteLine(ex.Message.ToString());

                }
                finally
                {
                    sqlConnection.Close();

                }

        }
    }
}
